package tools;



import HtServer.meeting.MeetingItem;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

public class Tools {

    /**
     * 根据list，随机抽取指定数量的id
     * （1不会被抽中，2一定会被抽中，其他随机）
     */
    public static  List Random(LinkedList<MeetingItem> list, int NUM) {
/*
        LinkedList<MeetingItem> list_ = new LinkedList<>(list);


        // 打乱ID列表
        Collections.shuffle(list_);


        return list_.subList(0, Math.min(NUM, list_.size()));*/

        // 将所有type为2的项目挑选出来
        List<MeetingItem> selectedItems = list.stream()
                .filter(item -> item.getRandomtype() == 2)
                .collect(Collectors.toList());

        // 过滤掉type为1的项目
        List<MeetingItem> filteredList = list.stream()
                .filter(item -> item.getRandomtype() != 1)
                .filter(item -> item.getRandomtype() != 2 )

                .collect(Collectors.toList());

        // 打乱剩余的项目
        Collections.shuffle(filteredList);

        // 从剩余的项目中随机抽取指定数量的项目
        int remainingNum = NUM - selectedItems.size();
        if (remainingNum > 0) {
            selectedItems.addAll(filteredList.subList(0, Math.min(remainingNum, filteredList.size())));
        }

        return selectedItems;
    }

    public static void main(String[] args) {

//        LinkedList<Integer> mutableList = new LinkedList<>(List.of(1, 2, 3, 4, 5));
//        Random(mutableList, 3);
//        System.out.println(mutableList);

        LinkedList<MeetingItem> meetingItems = new LinkedList<>();
        // 添加示例数据
        MeetingItem mi   = new MeetingItem();
        mi.setName("Meeting 1");
        mi.setRandomtype(1);
        meetingItems.add(mi);


        MeetingItem mi2   = new MeetingItem();
        mi2.setName("Meeting 2");
        mi2.setRandomtype(1);
        meetingItems.add(mi2);

        MeetingItem mi3   = new MeetingItem();
        mi3.setName("Meeting 3");
        mi3.setRandomtype(1);
        meetingItems.add(mi3);

        MeetingItem mi4   = new MeetingItem();
        mi4.setName("Meeting 4");
//        mi4.setRandomtype(1);
        meetingItems.add(mi4);

        MeetingItem mi5   = new MeetingItem();
        mi5.setName("Meeting 5");
//        mi5.setRandomtype(3);
        meetingItems.add(mi5);


        System.out.println("Randomly selected Meeting Items: " + meetingItems);
        List<MeetingItem> randomMeetingItems = Random(meetingItems, 5);
        System.out.println("Randomly selected Meeting Items: " + randomMeetingItems);

    }
}
